package com.qkl.xiatang.app.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
@Slf4j
public class AppThreadPoolService {

    @Resource(name = "applicationThreadPool")
    private ThreadPoolTaskExecutor appThreadPool;


    @Resource(name = "applicationThreadSchedulePool")
    private ThreadPoolTaskScheduler appThreadSchedulePool;


    public void execute(Runnable runnable){
        appThreadPool.execute(runnable);
    }

    public void scheduleMinute(Runnable runnable,long delayMinute){
        Date startTime = new Date(System.currentTimeMillis() + delayMinute * 60 * 1000);
        appThreadSchedulePool.schedule(runnable,startTime);
    }

}
